<!--
 * @Author: Cenven
 * @Date: 2021-07-01 09:45:16
 * @Description: 北京泓深教育发展有限公司
 * @Descripttion: 
 * @version: @Lastest
 * @LastEditTime: 2021-07-01 10:55:56
 * @CopyRight: 北京泓深教育发展有限公司
-->
<template>
  <div class="question-paper">
    <div class="paper_container">
      <p class="paper_name">{{ paperDetail.name }}</p>
      <div class="paper_info">
        <span>满分：{{ paperDetail.total }}分</span>
        <span class="line"></span>
        <span>限时：{{ paperDetail.span }}分钟</span>
        <span class="line"></span>
        <span>题目：{{ paperDetail.questionNum }}道</span>
      </div>
      <ul class="paper_question_list">
        <li
          class="question_item"
          v-for="(item, index) in paperDetail.questions"
          :key="'paperDetail.questions' + index"
        >
          <div class="item_left">{{ item.name || formatQuestionType(item.questionType) }}（{{item.questionGroupTestQuestionList.length * item.score}}分）</div>
          <div class="item_right">共{{ item.questionGroupTestQuestionList.length }}道题</div>
        </li>
      </ul>
      <div class="start_btn" @click="startAnswering">开始考试</div>
      <p class="test_tips">*提示：中途退出考试会影响评分，请谨慎退出哦～</p>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
import {
  getQuestionBankPaperDetail,
  getQuestionBankPaperList
} from "~/api/v2-question-bank/question-bank.js";
export default {
  name: "question-paper",
  components: {},
  data() {
    return {
      paperDetail: {
        answerCount: 0,
        author: "",
        createTime: 0,
        diff: 1,
        generateType: 1,
        id: 0,
        introduce: "",
        isUse: 1,
        name: "",
        passScore: 0,
        questionGroupId: 0,
        remind: "",
        span: 0,
        subName: "",
        total: 0,
        type: 1,
        updateTime: 0,
        questions: []
      },
      questionTypeOptions: [
        { id: 1, label: "单选题" },
        { id: 2, label: "多选题" },
        { id: 3, label: "简答题" },
        { id: 4, label: "填空题" },
        { id: 5, label: "判断题" }
      ] //题型选项配置
    };
  },
  computed: {
    ...mapState({
      user_info(state) {
        return state.user_info;
      },
      token(state) {
        return state.token;
      },
      is_loading(state) {
        return state.is_loading;
      }
    }),
    /* 题套Id */
    questionId() {
      return this.$route.query.id;
    },
    /* 试卷Id */
    testId() {
      return this.$route.query.testId;
    },
    /* 类型（0章节练习 试卷类型 1专项训练 2模拟考试 3真题训练） */
    type() {
      return this.$route.query.type;
    }
  },
  watch: {},
  methods: {
    ...mapMutations(["SET_IS_LOADING"]),
    formatQuestionType(questionType){
      let obj = this.questionTypeOptions.find(item=>item.id == questionType);
      if(obj){
        return obj.label;
      }
    },
    startAnswering() {
      this.$router.push({
        path: "/question-test",
        query: {
          id: this.questionId,
          type: this.type,
          testId: this.testId
        }
      });
    },
    /* 获取试卷详情 */
    async getTestPaper() {
      let result = await getQuestionBankPaperList({ id: this.testId });
      // console.log("获取试卷内容：", result);
      if (result && result.data && result.data.code == 200) {
        const { rows } = result.data.data;
        if (rows.length > 0) {
          this.paperDetail = rows[0];
          this.getTestPaperDetail();
        }
        this.SET_IS_LOADING(false);
      } else {
        this.SET_IS_LOADING(false);
      }
    },
    /* 获取试卷试题 */
    async getTestPaperDetail() {
      let params = {
        questionGroupPaperId: this.testId,
        questionGroupId: this.questionId,
        questionType: this.type
      };
      let result = await getQuestionBankPaperDetail(params);
      // console.log("获取试卷试题：", result);
      if (result && result.data && result.data.code == 200) {
        let originData = result.data.data;
        this.paperDetail = {
          ...this.paperDetail,
          questions: originData
        };
        this.SET_IS_LOADING(false);
      } else {
        this.SET_IS_LOADING(false);
      }
    },
    initPage() {
      this.getTestPaper();
    }
  },
  created() {
    this.initPage();
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>
.question-paper {
  width: 100%;
  min-height: 100vh;
  box-sizing: border-box;
  padding: 70px 0;
  .paper_container {
    width: 800px;
    background: #fff;
    border-radius: 10px;
   
    margin: 0 auto;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.05);
    padding: 0 100px;
    box-sizing: border-box;
    .paper_name{
      font-size: 30px;
      line-height: 80px;
      font-weight: bold;
      text-align: center;
    }
    .paper_info{
      display: flex;
      // justify-content: space-around;
      justify-content: space-between;
      font-size: 16px;
      line-height: 22px;
      .line {
        display: inline-block;
        width: 1px;
        height: 22px;
        background-color: #abafb3;
      }
    }
    .paper_question_list{
      width: 100%;
      min-height: 300px;
      padding: 20px 0;
      box-sizing: border-box;
      .question_item{
        border-bottom: 1px solid #e9edf5;
        display: flex;
        justify-content: space-between;
        // line-height: 50px;
        padding: 15px 0;
        line-height: 20px;
        font-size: 14px;
        &:last-child {
          border-bottom: none;
        }
        .item_left{
          width: 76%;
        }
        .item_right{
          width: 24%;
          text-align: right;
        }
      }
    }
    .start_btn{
      width: 100%;
      margin: 0 auto;
      height: 60px;
      line-height: 60px;
      text-align: center;
      background-color: var(--theme-color);
      border-radius: 30px;
      font-size: 30px;
      color: #ffffff;
      cursor: pointer;
    }
    .test_tips{
      width: 100%;
      margin: 0 auto;
      padding: 20px 30px;
      color: var(--theme-color);
      font-size: 16px;
    }
  }
}
</style>
